<script setup>
import { ref, computed, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import { UserFilled, List, Connection, Money } from '@element-plus/icons-vue'

const route = useRoute()
const activeMenu = computed(() => route.path)

// 用户信息
const userInfo = ref(JSON.parse(localStorage.getItem('userInfo')))

const roleMap = {
  'admin': '管理员',
  'user': '普通用户'
}
</script>

<template>
  <div class="profile-container">
    <div class="profile-layout">
      <!-- 左侧菜单 -->
      <div class="profile-sidebar">
        <div class="user-info">
          <div class="avatar-container">
            <el-avatar :size="80" :src="`/api/Userfile/${userInfo.avatar}`" class="user-avatar" />
          </div>
          <div class="user-name">
            <div class="name-role">
              <el-tag size="large" class="name-tag">{{ userInfo.name }}</el-tag>
              <el-tag type="success" size="large" class="role-tag">{{ roleMap[userInfo.role] }}</el-tag>
            </div>
          </div>
        </div>
        <el-menu class="profile-menu" :default-active="activeMenu" router>
          <el-menu-item index="/front/profile/info">
            <el-icon>
              <UserFilled />
            </el-icon>
            <span>个人信息</span>
          </el-menu-item>
          <el-menu-item index="/front/profile/adoption-records">
            <el-icon>
              <List />
            </el-icon>
            <span>领养记录</span>
          </el-menu-item>
          <el-menu-item index="/front/profile/surrender-records">
            <el-icon>
              <Connection />
            </el-icon>
            <span>送养记录</span>
          </el-menu-item>
          <el-menu-item index="/front/profile/donation-records">
            <el-icon>
              <Money />
            </el-icon>
            <span>捐赠记录</span>
          </el-menu-item>
        </el-menu>
      </div>

      <!-- 右侧内容区 -->
      <div class="profile-content">
        <router-view />
      </div>
    </div>
  </div>
</template>

<style scoped>
.profile-container {
  background-color: #f5f7fa;
  min-height: calc(100vh - 60px);
  padding: 30px;
}

.profile-layout {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  overflow: hidden;
  min-height: calc(100vh - 120px);
}

.profile-sidebar {
  width: 250px;
  border-right: 1px solid #ebeef5;
  background-color: #fff;
  transition: all 0.3s ease;
}

.user-info {
  padding: 30px 20px;
  text-align: center;
  border-bottom: 1px solid #ebeef5;
  background: linear-gradient(to bottom, #f8f9fa, #fff);
}

.avatar-container {
  margin-bottom: 16px;
}

.user-avatar {
  border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease;
}

.user-avatar:hover {
  transform: scale(1.05);
}

.user-name {
  display: flex;
  align-items: center;
  justify-content: center;
}

.name-role {
  display: flex;
  gap: 8px;
  align-items: center;
}

.name-tag, .role-tag {
  padding: 6px 12px;
  font-weight: 500;
}

.name-tag {
  background-color: #e6f0ff;
  color: #409eff;
  border-color: #b3d8ff;
}

.role-tag {
  background-color: #e6fff2;
  border-color: #b3ffdb;
}

.profile-menu {
  border-right: none;
  padding: 16px 0;
}

.profile-menu :deep(.el-menu-item) {
  height: 50px;
  line-height: 50px;
  margin: 4px 16px;
  border-radius: 8px;
  transition: all 0.3s ease;
}

.profile-menu :deep(.el-menu-item.is-active) {
  background-color: #ecf5ff;
  color: #409eff;
}

.profile-menu :deep(.el-menu-item:hover) {
  background-color: #f5f7fa;
}

.profile-content {
  flex: 1;
  padding: 30px;
  background-color: #fff;
  overflow: auto;
}
</style>